function getImgUrl(url,func){
	var that = this;
	this.url = url;
	// mui.alert(this.url);
	this.func = func;
	if (mui.os.plus) {
		var a = [{
			title: "拍照"
		}, {
			title: "从手机相册选择"
		}];
		plus.nativeUI.actionSheet({
			title: "头像上传",
			cancel: "取消",
			buttons: a
		}, function(b) { 
			/*actionSheet 按钮点击事件*/
			switch (b.index) {
				case 0:
					break;
				case 1:
					// getImages(); /*拍照*/
					that.paizhao(); /*拍照*/
					break;
				case 2:
					// galleryImages(); /*打开相册*/
					that.shangce();
					break;
				default:
					break;
			}
		})
	}
	//拍照
	this.paizhao = function(){
		var mobileCamera=plus.camera.getCamera();
		mobileCamera.captureImage(function(e){
		    plus.io.resolveLocalFileSystemURL(e,function(entry){
		        var path=entry.toLocalURL()+'?version='+new Date().getTime();
				that.shangchuantouxiang(path)
		    },function(err){
		        console.log("读取拍照文件错误");
		    });
		},function(e){
		    console.log("er",err);
		},function(){
		    filename:'_doc/head.png';
		});
	}
	//选择相册
	this.shangce = function(){
		plus.gallery.pick(function(a){
		    plus.io.resolveLocalFileSystemURL(a,function(entry){
		        plus.io.resolveLocalFileSystemURL('_doc/',function(root){
		            root.getFile('head.png',{},function(file){
		                //文件已经存在
		                file.remove(function(){
		                    console.log("文件移除成功");
		                    entry.copyTo(root,'head.png',function(e){
		                        var path=e.fullPath+'?version='+new Date().getTime();
														     shangchuantouxiang(path) 
		                    },function(err){
		                        console.log("copy image fail: ",err);
		                    });
		                },function(err){
		                    console.log("删除图片失败：（"+JSON.stringify(err)+")");
		                });
		            },function(err){
		                //打开文件失败
		                entry.copyTo(root,'head.png',function(e){
		                    var path=e.fullPath+'?version='+new Date().getTime();
		                    uploadHeadImg(path);
		                },function(err){
		                    console.log("上传图片失败：（"+JSON.stringify(err)+")");
		                });
		            });
		        },function(e){
		            console.log("读取文件夹失败：（"+JSON.stringify(err)+")");
		        });
		    });
		},function(err){
		    console.log("读取拍照文件失败: ",err);
		},{
		    filter:'image'
		});
	}
	//上传图片
	this.shangchuantouxiang = function(path){
		var  image =new  Image();
		image.src=path;
		image.onload=function(){
			var  image =new  Image();
			image.src=path;
			image.onload=function(){
										  	var imgData=that.getBase64Image(image); 
											  	mui.ajax(that.url,{
											data:{
												file:imgData
											},
											dataType:'json',//服务器返回json格式数据
											type:'post',//HTTP请求类型
											timeout:10000,//超时时间设置为10秒；
											success:function(data){
												if(that.func){
													that.func(data);
												}
											},
											error:function(data){
												mui.alert("头像上传失败")
											}
										});  
			}
		}
	}
	//转化成base64
	this.getBase64Image = function(img){
							// console.log(img.getBase64Image());
			      var canvas=document.createElement("canvas");
			      var width=img.width;
			      var height=img.height;
							var size = img.size;
						
							
			      if(width>height){
			          if(width>500){
			              height=Math.round(height*=500/width);
			              width=500;
			          }
			      }else{
			          if(height>500){
			              width=Math.round(width*=500/height);
			          }
			          height=500;
			      }
					
			      canvas.width=width;
			      canvas.height=height;
			      var ctx=canvas.getContext('2d');
			      ctx.drawImage(img,0,0,width,height);
					
			      var dataUrl=canvas.toDataURL('image/png',0.8);
			      return dataUrl.replace('data:image/png:base64,','');
			  }
}
function diaojishi(zong,func){
	if(!zong){
	     zong = 60;
	 }
	 this.zong = zong;
	 this.func = '';
	 if(func){
	     this.func = func;
	 }
	 var that = this;
	
	this.kais = function () {
	    that.zong--;
	    if(that.zong>=0){
	        if(that.func){
	            that.func(that.zong);
	        }
	        setTimeout(that.kais,1000);
	    }
	}
	this.kais();
}